readf <- function(expno, nexp=1){
#---------------------------------------------------------------------
# subfunctions
  # Read one file
  readfile <- function(ifile){
    tmp <- read.csv(file=ifile,sep=",",header=F)
    invisible(tmp)
  }
    
  # Compute ObjectiveFitnessCorrelation
  ofcor <- function(objf, subjf){
    stopifnot(dim(objf)==dim(subjf))
    ng <- dim(objf)[1]
    result <- array(dim=ng)
    for (i in 1:ng) {
        if ((var(as.vector(t(objf[i,-1])))==0) || (var(as.vector(t(subjf[i,-1])))==0))
            result[i] = 0
        else
            result[i] = cor(as.vector(t(objf[i,-1])),as.vector(t(subjf[i,-1])))
    }
    invisible(result)
  }
#---------------------------------------------------------------------
# Main function
    bestobjf <- NULL        # best objective fitness
    bestsubjf <- NULL       # best subjective fitness
    ofc <- NULL             # objective-fitness correlation
    for (i in 1:nexp) {
        # Make file names
        ofile <- paste(expno,".objf.",i,sep="")
        sfile <- paste(expno,".subjf.",i,sep="")
        # Read files
        objf  <- readfile(ofile)
        subjf <- readfile(sfile)
        #print(paste("Read",ofile,sfile,", dimension: ",dim(objf)[1],dim(objf)[2]))
        # Compute results
        bestobjf <- cbind(bestobjf,apply(objf[,-1], 1, max))
        #bestsubjf <- cbind(bestsubjf,apply(subjf[,-1], 1, max))
        ofc <- cbind(ofc,ofcor(objf,subjf))
    }
  
    invisible(list(objf=bestobjf,ofc=ofc))
}

read0301 <- function(expno, nexp=1){
#---------------------------------------------------------------------
# subfunctions
  # Read one file
  readfile <- function(ifile){
    tmp <- read.csv(file=ifile,sep=" ",header=F)
    invisible(tmp[,3])
  }
#---------------------------------------------------------------------
# Main function
    bestobjf <- NULL        # best objective fitness
    for (i in 1:nexp) {
        # Make file names
        ofile <- paste(expno,".",i,sep="")
        # Read files
        objf  <- readfile(ofile)
        #print(paste("Read",ofile,sfile,", dimension: ",dim(objf)[1],dim(objf)[2]))
        # Compute results
        bestobjf <- cbind(bestobjf,objf)
    }
    ofc1 <- matrix(1,ncol=nexp,nrow=dim(bestobjf)[1])
  
    invisible(list(objf=bestobjf,ofc=ofc1))
}
